Function.RegisterNamespace("Test");

[Import("../../Source/Extensions.js/Number.js")]
[Fixture]
Test.Number=function(){
    [Fixture]
    function Equals(){
        [Fact]
        function ThrowsIfUnableToConvertExpectedToFloat(){
            var expected="Number.Equals: 'expected' must be a valid Number.";
            
            var actual=Record.Exception(function(){
                Number.Equals("float");
            });
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function DoesNotThrowIfExpectedConvertibleToFloat(){
            var actual=Record.Exception(function(){
                Number.Equals("1.float",1);
            });
            
            Assert.Null(actual);
        }
        
        [Fact]
        function ReturnsFalseIfUnableToConvertActualToFloat(){
            var actual=Number.Equals(1,"float");
            
            Assert.False(actual);
        }

        [Fact]
        function SetsReasonIfActualNotConvertibleToFloat(){
            var expected="Number.Equals: 'actual' was not convertible to Number.";
            var reason={};
            
            Number.Equals(1,"float",reason);
            var actual=reason.Value;
            
            Assert.Equal(expected,actual);
        }

        [Fact]
        function ProcessesNumbersIfActualConvertibleToFloat(){
            var actual=Record.Exception(function(){
                Number.Equals(1,"1.float");
            });
            
            Assert.Null(actual);
        }
        
        [Fact]
        function ReturnsFalseIfNumbersDontMatch(){
            var actual=Number.Equals(1,2);
        
            Assert.False(actual);
        }

        [Fact]
        function SetsReasonIfNumbersDontMatch(){
            var targetExpected=1;
            var targetActual=2;
            var expected=String.Format("Number.Equals: Numbers do not match. Expected '{0}', found '{1}'.",targetExpected,targetActual);
            var reason={};

            Number.Equals(targetExpected,targetActual,reason);
            var actual=reason.Value;
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function ReturnsTrueIfNumbersMatch(){
            var actual=Number.Equals(1,1);
            
            Assert.True(actual);
        }
        
    }
    
    [Fixture]
    function Trim(){
        [Fact]
        function DefaultsToZeroDecimalPlaces(){
            var expected=3;
            
            var actual=Number.Trim(3.14);
            
            Assert.Equal(expected,actual);
        }
        
        [Fact]
        function TrimsToSpecifiedDecimalPlace(){
            var expected=3.14;
            var target=3.1459;

            var actual=Number.Trim(expected,2);

            Assert.Equal(expected,actual);
        }        
    }

}